package jxd.myDwr;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.directwebremoting.extend.Calls;
import org.directwebremoting.extend.Handler;
import org.directwebremoting.extend.Remoter;
import org.directwebremoting.extend.Replies;

public class PlainCallHandler
  implements Handler
{
  protected PlainCallMarshaller plainCallMarshaller =null;

  protected Remoter remoter =null;

  public void handle(HttpServletRequest request, HttpServletResponse response)
    throws IOException
  {
    Calls calls = null;
    try
    {
      calls = this.plainCallMarshaller.marshallInbound(request, response);
    }
    catch (Exception ex)
    {
    	ex.printStackTrace();
      this.plainCallMarshaller.marshallException(request, response, ex);
      return;
    }

    Replies replies = this.remoter.execute(calls);
    this.plainCallMarshaller.marshallOutbound(replies, request, response);
  }

  public void setPlainCallMarshaller(PlainCallMarshaller marshaller)
  {
    this.plainCallMarshaller = marshaller;
  }

  public void setRemoter(Remoter remoter)
  {
    this.remoter = remoter;
  }
}